<template>
  <div class="msg_list">

    <van-list v-model="loading" :finished="finished" :error.sync="err" error-text="加载失败，点击这里重试" @load="getMessageList">

      <div class="box" v-for="(item, index) in list" :key="index" @click="jump(item)">
        <div class="top">
          <div class="shop_name">{{item.shop_name}}</div>
          <div class="time">{{$moment(Number(item.add_time) * 1000).format('YYYY-MM-DD HH:mm:ss')}}
          </div>
        </div>
        <div class="content">{{ item.summary}}</div>
        <van-cell title="点击查看详情" is-link :clickable="false" />
      </div>
    </van-list>
  </div>
</template>
<script>
import { Toast } from "vant";
export default {
  data () {
    return {
      list: [],
      page: 1,
      limit: 10,
      err: false,
      loading: false,
      finished: false,
    }
  },
  methods: {
    // 获取聊天列表
    getMessageList () {
      this.loading = true;
      if (this.loading) {
        Toast.loading({ message: "加载中...", forbidClick: true });
      }
      this.$axios
        .get(this.$api.noticelist, {
          params: {
            page: parseInt(this.list.length / this.limit) + 1, //页码
            limit: this.limit, //每页条数
          },
        })
        .then((res) => {

          if (res.data.code == 1) {
            Toast.clear();
            let result = res.data.data;
            this.list.push(...result.data);

            this.loading = false;
            if (result.data.length < this.limit) {
              this.finished = true; // 大于所有条数则结束加载
            }
            if (result.length > this.limit) this.page++;
          } else {
            // 加载失败时
            this.err = true;
            this.loading = false;
          }
        });
    },
    jump (item) {
      this.$router.push({ name: 'noticeDetail', query: { id: item.id } })
    }
  },
  watch: {

  },
  created () {

  },
  mounted () {

  },
  computed: {

  },
}
</script>
<style scoped lang='less'>
.msg_list {
  background: #f9f9f9;
  display: flex;
  flex-direction: column;
  align-items: center;
}
.box {
  width: 343px;
  border-radius: 6px;
  background: #ffffff;
  margin-top: 16px;
  padding: 12px;
  box-sizing: border-box;
  .top {
    display: flex;
    justify-content: space-between;
    align-items: center;
    .shop_name {
      font-size: 16px;

      color: #06021a;
    }
    .time {
      font-size: 12px;
      font-family: Microsoft YaHei-Regular, Microsoft YaHei;
      font-weight: 400;
      color: #06021a;
    }
  }
  .content {
    width: 319px;
    margin-top: 6px;
    padding-bottom: 12px;
    border-bottom: 1px solid #f1f1f1;
    font-size: 14px;
    color: #06021a;
    overflow: hidden; /*   超出容器的部分影响  */
    white-space: nowrap; /*  文本不换行   */
    text-overflow: ellipsis; /*  超出容器的文本显示省略号  */
  }
  .van-cell {
    margin-top: 12px;
    padding: 0;
  }
}
</style>
